<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="java.io.*,java.util.*,java.sql.*, com.animal.dao.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>修改密码</title>

<link rel="stylesheet" type="text/css" href="./bootstrap/css/bootstrap.min.css">
<link href="./bootstrap/css/styles.css" rel="stylesheet">
<link href="./bootstrap/css/my.css" rel="stylesheet">

</head>

<body οnlοad="javascript:document.getElementById('old_pw').focus();">
	<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
		<div class="container-fluid">
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#sidebar-collapse">
					<span class="sr-only">Toggle navigation</span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
				</button>
				<a class="navbar-brand" href="DailyFileManager.html"><span>实验动物</span>档案管理</a>
				<ul class="user-menu">
					<li class="dropdown pull-right">
						<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-user">
						</span> <%String id = String.valueOf(request.getSession().getAttribute("uid")); %><%=id %> <span class="caret"></span></a>
						<ul class="dropdown-menu" role="menu">
							<li><a href="http://www.cau.edu.cn"><span class="glyphicon glyphicon-user"></span> Profile</a></li>
							<li><a href="#"><span class="glyphicon glyphicon-cog"></span> Settings</a></li>
							<li><a href="login.jsp"><span class="glyphicon glyphicon-log-out"></span> Logout</a></li>
						</ul>
					</li>
				</ul>
			</div>			
		</div>
	</nav>
		
	<div id="sidebar-collapse" class="col-sm-3 col-lg-2 sidebar">
		<form role="search">
			<div class="form-group">
				<input type="text" class="form-control" placeholder="Search">
			</div>
		</form>
		<ul class="nav menu">
			<li class="parent ">
				<a href="#">
					<span class="glyphicon glyphicon-list"></span> 管理员信息  <span data-toggle="collapse" href="#sub-item-1" class="icon pull-right"><em class="glyphicon glyphicon-s glyphicon-plus"></em></span> 
				</a>
				<ul class="children collapse" id="sub-item-1">
					<li>
						<a class="" href="DailyPersonalInfo.jsp">
							<span class="glyphicon glyphicon-share-alt"></span> 个人信息
						</a>
					</li>
					<li>
						<a class="" href="DailyChangePassword.jsp">
							<span class="glyphicon glyphicon-share-alt"></span> 修改密码
						</a>
					</li>
				</ul>
			</li>
			
			<li class="parent ">
				<a href="#">
					<span class="glyphicon glyphicon-list"></span> 日常档案管理 <span data-toggle="collapse" href="#sub-item-2" class="icon pull-right"><em class="glyphicon glyphicon-s glyphicon-plus"></em></span> 
				</a>
				<ul class="children collapse" id="sub-item-2">
					<li>
						<a class="" href="DailyFileManagement.jsp">
							<span class="glyphicon glyphicon-share-alt"></span> 管理档案
						</a>
					</li>

				</ul>
			</li>
			
			<li role="presentation" class="divider"></li>
			<li><a href="login.jsp"><span class="glyphicon glyphicon-user"></span>登录页面</a></li>
		</ul>
		<div class="attribution">Created by <a href="#">软工第9组</a></div>
	</div><!--/.sidebar-->
		
	
	<div class="col-sm-9 col-sm-offset-3 col-lg-10 col-lg-offset-2 main">			
		<div class="row">
			<ol class="breadcrumb">
				<li><a href="DailyFileManager.html"><span class="glyphicon glyphicon-home"></span></a></li>
				<li class="active">管理员信息 > 修改密码</li>
			</ol>
		</div>
		
		<!-- 从这开始添加代码 -->
		
		<div class="row">
			<div class="col-lg-12" id="updataDiv">
				<!-- <iframe src="Home.html" width="100%" height="620px" ></iframe> -->
				<h3><center><b>管理员 修改密码</b></center></h3>
				<%
				//String id = (String)session.getAttribute("ID");
				id = String.valueOf(request.getSession().getAttribute("uid"));
				String the_1;
				request.setAttribute("uid", id);
				String queryStr = "select Password from animalfile09_archvist where ID=?";
				Connection conn = Connect.getCon();
				PreparedStatement pstmt = conn.prepareStatement(queryStr);
				ResultSet rs = null;
				pstmt.setString(1,id);
				rs = pstmt.executeQuery();
				if (rs.next()){
				the_1 = rs.getString(1);
				request.setAttribute("upw", the_1);
				}
				else{}
				pstmt.close();
				conn.close(); 
				%>
				
				<ul id="nav">
  				<li><a href="#">输入旧密码</a></li>
  				<li><input class="form-control"  placeholder="当前密码" ID="old_pw" type="text" onblur ="check_pw()"></li>
				</ul>
								
				<ul id="nav">
  				<li><a href="#">输入新密码</a></li>
  				<li><input class="form-control"  placeholder="新密码" ID="new_pw" type="text" maxlength=11 onblur ="check_npw()"></li>
				</ul>
				
				<ul id="nav">
  				<li><a href="#">确认新密码</a></li>
  				<li><input class="form-control"  placeholder="新密码" ID="new_pw2" type="text" maxlength=11 onblur ="check_npw2()"></li>
				</ul>
				
				<div align="center">
				<input type="button" value="确认修改" id="save" class="btn btn-primary" onclick="getData()"> 
				</div>
			</div>
		</div>
	</div>
	
	<script src="./bootstrap/js/jquery-3.1.0.min.js"></script>
	<script src="./bootstrap/js/bootstrap.min.js"></script>

	<script type="text/javascript">
	function show(){
		var pw = document.getElementById("new_pw");
		pw.type="text";	
	}
	function check_pw(){
		var pw = document.getElementById("old_pw").value;
		var P = "${upw}";
		if(pw==P){}
		else{
			document.getElementById("old_pw").value="";
			alert("密码错误，请重新输入！");
		} 	
	}
	//判断新密码
	function check_npw(){
		var pw = document.getElementById("new_pw").value;
		var P = "${upw}";
		console.log(P);
		if(pw==P){
			document.getElementById("new_pw").value="";
			alert("新密码不能与原密码一致！");
		}
		else{}
	}
	function check_npw2(){
		var pw = document.getElementById("new_pw").value;
		var npw = document.getElementById("new_pw2").value;
		var P = "${upw}";
		console.log(P);
		if(pw==npw){}
		else{
			document.getElementById("new_pw2").value="";
			alert("新密码输入错误！");
		}
	} 	
	function getData() {
		//1 创建Ajax引擎对象
			var ajax;
			var npw = document.getElementById("new_pw2").value;
			var id = "${uid}";
			if(window.XMLHttpRequest){
				//火狐
				ajax = new XMLHttpRequest();
			}else if (window.ActiveXObject) {
				//IE6、7
				ajax = new ActiveXObject("Msxml2.XMLHTTP");
			}
			
		//2 复写onreadystatement函数
		//获取元素对象
			ajax.onreadystatechange=function(){

				//4 判断Ajax状态码
				if(ajax.readyState == 4){
					
					//5 判断响应状态码
					if(ajax.status == 200){
						//获取响应内容
						var result = ajax.responseText;
						//修改元素内容
						alert("密码修改成功！");
						document.getElementById("old_pw").value="";
						document.getElementById("new_pw").value="";
						document.getElementById("new_pw2").value="";
						
					}else if(ajax.status == 404){
						var showdiv = document.getElementById("updataDiv");
						showdiv.innerHTML = "请求资源不存在";
					}else if(ajax.status == 500){
						var showdiv = document.getElementById("updataDiv");
						showdiv.innerHTML = "服务器繁忙";
					}
				}
				
			}
		
		//3 发送请求
			ajax.open("GET","DailyUpdatePassword.jsp?PW="+npw+"&I="+id,false);
			ajax.send(null); 	
	}
	</script>

</body>

</html>
